#include<iostream>//根据前序遍历和中序遍历确定二叉树
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
struct Treenode
{
    char data;
    Treenode *parent,*left,*right;
};
Treenode *root=NULL;
//Treenode *dic_node[100];
string pre_travel;
string in_travel;
int n;
Treenode *build_tree(int l1,int r1,int l2,int r2,Treenode *parent)
{
    char root_data=pre_travel[l1];
    Treenode *temp=new Treenode;
    temp->data=root_data;
    temp->parent=parent;
    int root_index=in_travel.find(root_data);
    if(l2<root_index)temp->left=build_tree(l1+1,l1+1+root_index-l2-1,l2,root_index-1,temp);
    if(root_index<r2)temp->right=build_tree(l1+1+root_index-l2,r1,root_index+1,r2,temp);
    return temp;
}
void post_order(Treenode *root)
{
    if(root==NULL)
        return;
    post_order(root->left);
    post_order(root->right);
    cout<<root->data<<" ";
}
void print(Treenode *root)
{
    queue<Treenode *>q;
    q.push(root);
    while(!q.empty())
    {
        Treenode *temp=q.front();
        q.pop();
        printf("%c ",temp->data);
        if(temp->left!=NULL)
        {
            printf("的左孩子为：%c ，",temp->left->data);
            q.push(temp->left);
        }
        else printf("的左孩子为：NULL，");
        if(temp->right!=NULL)
        {
            printf("的右孩子为：%c， \n",temp->right->data);
            q.push(temp->right);
        }
        else printf("的右孩子为：NULL\n");
    }
}
int main()
{
    cin>>pre_travel>>in_travel;
    n=pre_travel.length();
    root=build_tree(0,n-1,0,n-1,NULL);
    //post_order(root);
    print(root);
    cout<<endl;
    return 0;
}